﻿<extend name="Public:base" />
<block name="body">
    <style type="text/css">
       .input-group {
        /* position: relative; */
        display: table;
        border-collapse: separate;
        width: 200px;
    }   
    .col-sm-5{ position:relative; }
    .sy_ccs1{ position: absolute; left:30px; top:10px;}
    .tags{width: auto;min-width: 377px;}
    .choice-brand{
        height: 28px;
    }
</style>
<!--引入弹窗插件-->
<include file="Public:artdialog" />

<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
        </script>
        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
 <span style="color:#428bca">{$parent_nav.name}</span>
            </li>
            <li class="active">{$one_nav.name}</li>
        </ul><!-- .breadcrumb -->
    </div>
            <style type="text/css">
                .page-content {
            padding: 0px 24px 24px;
                }
                
                .porlets-content_title {
                    height: 49px;
                    background: #b6d1f2;
                }
                .col-md-12 .icon-table{
                    color: #FFFFFF;
                    font-size: 18px;
                    font-weight: bolder;
                    line-height: 49px;
                }
            </style>
    <div class="page-content">

        <form action="{:U('PreOrder/PreOrderList')}" method="post" id="searchForm">
            <input  type="hidden" name="brand_ids" value="" id="brand_ids">
       
            <div class="row">
                <div class="col-md-12">
                    <div class="block-web">
                  <div class="row" >
                    <div style="padding: 20px 0;background: #e9f0f9;height:100%;">
                         <div class="form-group" style="float: left;">
                            <div class="input-group col-sm-3">
                             <input class="form-control" id="title" type="text" name="title" placeholder="请输入搜索条件/自编码/条形码" size="15">
                         </div>
                     </div>
                     <div class="form-group" style="float: left;">
                        <div class="input-group col-sm-3">
                         <input class="form-control" id="goods_name" type="text" name="goods_name" placeholder="请输入商品名">
                     </div>
                 </div>

                   <div class="form-group" style="float: left;">
                        <div class="input-group col-sm-3">
                         <input class="form-control" id="chinese_goods_name" type="text" name="chinese_goods_name" placeholder="请输入中文商品名">
                     </div>
                 </div>
                 <div class="form-group" >
                    <div class="col-sm-12">
                        <div class="tags" id="brand_label">
                           <button type="button" class="btn btn-sm btn-info choice-brand"  onclick="_esOpendialogmini('{:U('PreOrder/PreOrderbrand')}','选择品牌','xuanzepinpai')"> 选择品牌</button>

                       </div> 
                        <div class=""  style="float: right; margin:0 20px" >
                         <a href="#" class="btn btn-sm btn-info  radius-4" onclick="_es_openDilog902('{:U('PreOrder/confirm_pre_order')}','确定预订单','quedingyudingdan')">
                           确定预订单
                           <span class="badge badge-pink" id="pre_order_count">+0</span>
                         </a>  
                      </div>
                   </div>
                   <button type="button" class="btn btn-sm btn-info"  onclick="load()"> 搜索</button>
                   <button type="button" class="btn btn-sm btn-info" onclick="sub_all()"> 查看所有</button>
                  <div style="clear:both;"></div>
                   <!-- <button type="button" class="btn btn-info" onclick="export_excel()"> 导出EXCEL</button> -->

               </div>
              </div>
                   <div class="porlets-content">
                    <div class="porlets-content_title">
                        <div class="row" >
                            <div class="col-md-12 icon-table">{$one_nav.name}</div>
                        </div>
                    </div>
                <div class="table-responsive">
                    <div id="order_list_item_content">
                        <div class="item-list-bd" style="height:100px;line-height:100px;text-align:center;">
                            <img src="__PUBLIC__/admin/images/load3.gif" />
                            加载中...
                        </div>
                    </div>
                </div><!--/table-responsive-->
        </div><!--/block-web-->
    </div><!--/col-md-12-->
</div>
</form>
</div>
</div>
<script type="text/javascript" src="__PUBLIC__/laydate/laydate.dev.js"></script>
<script type="text/javascript">
    var cookiename_brand="brand2_<?php echo UID; ?>";
    var cookiename2="pre_order_<?php echo UID; ?>";
    $(function(){
        //初始化
        RCWBrand();
        //预订单数量
        pre_order_count();
        goSearch("#searchForm","order_list_item_content");

        $(document).keydown(function(event){ 
        if(event.keyCode==13){ 
        load(); 
        } 
            })
      
    });
    
    function pre_order_count(){
      var ojson = [];
          //获取cookie值 
          var _list=getCookie(cookiename2);
          if(_list!=""){
            ojson=JSON.parse(_list);
           } 
           if( ojson == null){return;}
          var count = ojson.length;
          $('#pre_order_count').html('+'+count);
    }

    function load(){
      goSearch("#searchForm","order_list_item_content");
    }

    function toParentChilder(id){
        $('#parent_id').val(id);
        goSearch("#searchForm","order_list_item_content");
    }

    function clock_load_dialog(){
     setTimeout(function(){
        var win=    art.dialog.opener;
        win.load();
        top.art.dialog().close();
    },800);
 }

function sub_all(){
    $('input[type=text]').val(['']);
    $('input[type=hidden]').val(['']);
    $('select').val('');
    //清空html
    $('#brand_label').children('span').remove();
    //删除cookie
    setCookie(cookiename_brand,"",-10);
    load();
}

 function _es_openDilog90(url, title,id){ 
   art.dialog.open(url, { title: title, width: '1200px', height: '90%', opacity: 0.2, id: id, fixed: true, close:function(){load();}  });
}
function _es_openDilog902(url, title,id){
   art.dialog.open(url, { title: title, width: '1200px', height: '90%', opacity: 0.2, id: id, fixed: true, close:function(){pre_order_count();}  });
}
function _esOpendialogmini(url, title,id){

    var mydialog=art.dialog.open(url,{title:title, width:'800px', height:'500px', opacity: 0.2, id: "add_edit_id",
      ok: function () { 
        this.close();
        RCWBrand();
        return false;
    },
    okVal:'确定'
    });  
}

function RCWBrand(){
   var ojson=[],lsjson=[],json=[],del_json=[]; 
   var htl="";
    //获取cookie值 
    var _list=getCookie(cookiename_brand);
    if(_list!=""){
      ojson=JSON.parse(_list);
  }
    //当前已经存在的商品信息 
    $("#brand_label").find('span').each(function(){
        var _json=$(this).attr("field");
        var _json="{"+_json+"}";
        var tmp =JSON.parse(_json);
        if(tmp != ""){
                  lsjson.push(tmp);  //当前特价商品信息
              }
          });
    
    if(ojson == null){ 
       ojson = {};
    }
    //过滤存在的品牌信息 
    for(var i=0;i<ojson.length;i++){
        var flg=false;
        for(var j=0;j<lsjson.length;j++){
            if(ojson[i].brand_id==lsjson[j].brand_id){
                flg=true;
                break;
            }
        }
        if(!flg){json.push(ojson[i]);}
    }
    //看是否有删除的品牌信息 
    for(var j=0;j<lsjson.length;j++){
       var flg=false;
       for(var i=0;i<ojson.length;i++){
        if(ojson[i].brand_id==lsjson[j].brand_id){
            flg=true;
            break;
        }
    }
    if(!flg){del_json.push(lsjson[j]);}
    }

    //删除不存在的标签
    if(del_json.length!=0){
         for(var i=0;i<del_json.length;i++){
          var _barnd = $('#brand_'+del_json[i].brand_id);
          _barnd.html('');
        }  
    }

    if(json==null)return;
     htl= "";
    for(var i=0;i<json.length;i++){
        htl +='<span class="tag" id="brand_'+json[i].brand_id+'" field=\'"brand_id":"'+json[i].brand_id+'","brand_name":"'+json[i].brand_name+'"\'>'+json[i].brand_name+'<button type="button" onclick="del_brand(this)" class="close">×</button></span>'; 
    }   
    if(htl!=""){
        $("#brand_label").append(htl); 
    } 
    //将brand_id 保存到form中
    brand_id_save_to_form();
}

function brand_id_save_to_form(){
   var _brand_ids ='';
   var _list=getCookie(cookiename_brand);
   if(_list==""){
      $('#brand_ids').val(''); return;
  }
   ojson=JSON.parse(_list);
   if(ojson == null){
     ojson = {};
   }
  for(var i=0;i<ojson.length;i++){
     _brand_ids += (_brand_ids==""?'':',')+ ojson[i]['brand_id'];
 }
 $('#brand_ids').val(_brand_ids);

}
//点击删除brand标签
function del_brand(_this){
    //删除该条html
    var ojson=[],new_json = [];
    var _json = $(_this).parent('span').attr('field');
    $(_this).parent('span').remove();
   //删除cookie中的这条记录
      //获取该条记录
      var _json="{"+_json+"}";
      var tmp =JSON.parse(_json);
      var _list=getCookie(cookiename_brand);
      if(_list!=""){
          ojson=JSON.parse(_list);
      } 
      for(var i=0;i<ojson.length;i++){
        var flag = false;
        if(ojson[i].brand_id == tmp.brand_id){
            flag = true;
        }
        if(!flag){new_json.push(ojson[i]);}
    }
     //重新保存cookie
     setCookie(cookiename_brand,"",-10);
     if(new_json.length>0){
        var _db=JSON.stringify(new_json);
        setCookie(cookiename_brand,_db,1);
    }
     //将brand_id 保存到form中 
     brand_id_save_to_form();
 }

    //写入cookie
    function setCookie(c_name, value, expiredays){
        if(expiredays < 0){
            localStorage.removeItem(c_name);
        }
       localStorage.setItem(c_name,value); //存储名字为name值为caibin的变量
   }
//读取cookie   
function getCookie(c_name){
    return  localStorage.getItem(c_name);
}
</script>
</block>
